import java.util.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;

public class ScreenedClientList extends AbstractTableModel{
	private ArrayList<ScreenedClient> data;
	private String[] columnNames = {"First Name", "Last Name", "Date of Birth", "Date Screened"};
	private ScreenedClient client;

	
	public ScreenedClientList() {
   	data = new ArrayList<ScreenedClient>();
		
	}
	
	@Override
	public String getColumnName(int column) {
   	 return columnNames[column];
	}

	@Override
	public int getColumnCount() {
	    return columnNames.length;
	}
	
	@Override
	public int getRowCount() {
	    return data.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {//each case statment fills a column of the list at the designated row
 	   client = (ScreenedClient)data.get(rowIndex);
	  		switch (columnIndex) {
   	 		case 0:
    	    		return client.getFirstName();
    			case 1:
     	  			return client.getLastName();
				case 2:
					return client.getDateOfBirth();
				case 3:
					return client.getScreenDate();
				default:
     	  			return null;
      	}
	}

	public void addClient(ScreenedClient client){ //adds a client and refreshes the table
		data.add(client);
		this.fireTableDataChanged();
	
	}
	

	public void removeClient(ScreenedClient client){ //removes a client and refreshes
 	  	if(!data.isEmpty()){     
			 data.remove(client);
			 this.fireTableDataChanged();
		}
	}
	
	public void printList(){
			System.out.println("Test:" + data.toString());
	}
	
	public Object getIndexOf(int i){
		if(!data.isEmpty()){
			return data.get(i);
		}
		else{
			return null;
		}
	}
	
	public void removeAt(int i){ //removes a client but this uses index instead of an object
		if(!data.isEmpty()){
			data.remove(i);
			this.fireTableDataChanged();
		}
	}
	
		
}